<template>
	<view>
		<uni-card :title="item.id+''" thumbnail="" :extra="item.date" :note="item.id"
			v-for="(item,index) in commentList">
			{{item.content}}
		</uni-card>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				commentList: [],
				id: 0
			}
		},
		onLoad(option) {

			this.id = 0
			this.reload()
		},
		onPullDownRefresh() {
			this.reload()
		},
		onReachBottom() {
			uni.showLoading({
				title: '加载中...',
				mask: false
			});
			this.loadmore()

		},
		methods: {
			reload() {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/message/list',
					method: 'POST',
					data: {
						id: this.id
					},
					success: res => {
						this.commentList = [...res.data.list].reverse()
						this.id++
					},
					fail: () => {},
					complete: () => {
						uni.stopPullDownRefresh()
					}
				});
			},
			//加载新的一页，并合并到原有数据中
			loadmore() {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/message/list',
					method: 'POST',
					data: {
						"id": this.id
					},
					success: res => {
						this.commentList = [...res.data.list].reverse()
						this.id++
						setTimeout(res => {
							uni.hideLoading()
						}, 1000)

					},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>

</style>